#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5005;
const int M = 1e6 + 7;
const int MX = 1e6;
const int MOD = 998244353;

int n, m;
int np[M], mnp[M];
vector<int> primes;
int a[N][3], b[N];
int g[1005][1005];
void init() {
  np[1] = 1;
  mnp[1] = 1;
  rep(i, 2, MX) {
    if (!np[i]) {
      primes.push_back(i);
      mnp[i] = 1;
    }
    for (int j : primes) {
      ll k = 1ll * j * i;
      if (k > MX) break;
      np[k] = 1;
      mnp[k] = j;
      if (i % j == 0) break;
    }
  }
  rep(i, 1, 1000) g[0][i] = g[i][0] = i;
  rep(i, 1, 1000) rep(j, i, 1000) g[i][j] = g[j][i] = g[j % i][i];
}
void factor(int a[3], int x) {
  a[0] = mnp[x];
  x /= mnp[x];
  a[1] = mnp[x];
  x /= mnp[x];
  while (x > 1000 && np[x]) {
    a[0] *= a[1];
    a[1] = mnp[x];
    x /= mnp[x];
  }
  a[2] = x;
}

int f(int a[3], int b) {
  int res = 1;
  rep(i, 0, 2) {
    int z = 1;
    if (a[i] > 1000)
      z = b % a[i] == 0 ? a[i] : 1;
    else
      z = g[a[i]][b % a[i]];
    if (z == 1) continue;
    b /= z;
    res *= z;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  cin >> n;
  rep(i, 1, n) {
    int x;
    cin >> x;
    factor(a[i], x);
  }
  rep(i, 1, n) cin >> b[i];
  rep(i, 1, n) {
    ll ans = 0;
    ll x = 1;
    rep(j, 1, n) {
      x = x * i % MOD;
      ll y = f(a[i], b[j]);
      ans = (ans + x * y % MOD) % MOD;
    }
    cout << ans << endl;
  }
  return 0;
}